* This file contains the code and references to the data files to reproduce
* all the figures that appear in the paper. Users should set their working
* directory in such a way that it calls the files from this folder.

* For example, pwd to see current directory, and cd "~/WarData" to change
* working directory.



/*Initial Setup*/

set more off



/*Figure 1 Setup*/

use "DailyCasualties.dta"

format date %tdMonCCYY
grstyle init
grstyle set plain, nogrid box

/*Figure 1a, Vietnam War*/
twoway ///
	(line day30_change date, lcolor(black) lpattern(solid) lwidth(thin)) if year>1960 & year<1975, ///
	ytitle("Casualties (% Change)", size(med)) 	///
	ylabel(0 (10) 40, labsize(small)) 	///
	xtitle("") xscale(off) xsc( noline ) fysize(60) /// 
	legend(off)
  	graph save casualtiesV, replace

twoway ///
	(bar foreignFirst date, color(gs6)) if year>1960 & year<1975, ///
	ytitle("MIP", size(med)) 	///
	ylabel(0 1, labsize(small)) 	///
	xtitle("Year", size(med)) ///
	xlabel(, labsize(small)) ///
	 fysize(20) ///
	legend(off)
  	graph save MIPV, replace

	
graph combine casualtiesV.gph MIPV.gph, xcommon cols(1) imargin(0 0 0 0) graphregion(margin(t=28 b=22))
	graph save TimeSeriesTrendV, replace

/*Figure 1b, Gulf War*/
	twoway ///
	(line day30_change date, lcolor(black) lpattern(solid) lwidth(thin)) if date>11139 & date<11535, ///
	ytitle("Casualties (% Change)", size(med)) 	///
	ylabel(0 (10) 40, labsize(small)) 	///
	xtitle("") xscale(off) xsc( noline ) fysize(60) /// 
	legend(off)
  	graph save casualtiesG, replace


twoway ///
	(bar foreignFirst date, color(black)) if date>11139 & date<11535, ///
	ytitle("MIP", size(med)) 	///
	ylabel(0 1, labsize(small)) 	///
	xtitle("Year", size(med)) ///
	xlabel(, labsize(small)) ///
	 fysize(20) ///
	legend(off)
  	graph save MIPG, replace

graph combine casualtiesG.gph MIPG.gph, xcommon cols(1) imargin(0 0 0 0) graphregion(margin(t=28 b=22))
	graph save TimeSeriesTrendG, replace

/*Figure 1c, War on Terror*/

	twoway ///
	(line day30_change date, lcolor(black) lpattern(solid) lwidth(thin)) if year>2000 & year<2007, ///
	ytitle("Casualties (% Change)", size(med)) 	///
	ylabel(0 (10) 40, labsize(small) nogrid) 	///
	xtitle("") xscale(off) xsc( noline ) fysize(60) /// 
	legend(off)
  	graph save casualtiesT, replace


twoway ///
	(bar foreignFirst date, color(black)) if year>2000 & year<2007, ///
	ytitle("MIP", size(med)) 	///
	ylabel(0 1, labsize(small) nogrid) 	///
	xtitle("Year", size(med)) ///
	xlabel(, labsize(small)) ///
	 fysize(20) ///
	legend(off)
  	graph save MIPT, replace

graph combine casualtiesT.gph MIPT.gph, xcommon cols(1) imargin(0 0 0 0) graphregion(margin(t=28 b=22))
	graph save TimeSeriesTrendT, replace


	
	
/*Figure 2a, House*/

use War_House_MIP
set scheme s1mono
twoway (rarea ul ll day30_change, fc(gs13) lc(bg)) ///
	(line b day30_change, lcolor(black) lpattern(solid)) ///
 (line ul2 day30_change, lcolor(black) lpattern(dot) lwidth(medthick)) ///
	(line ll2 day30_change, lcolor(black) lpattern(dot) lwidth(medthick))  ///
	(line b2 day30_change, lcolor(black) lpattern(dash)) ///
	(scatter where day30_change if day30_change>=-1 & day30_change<=30, ms(none) mlabel(pipe) mlabpos(0)), ///
	ytitle("Probability of Vote in Favor of President's Position" "House, All Votes", size(small)) ///
	ylabel(0 (0.2) 1, labsize(vsmall)) ///
	ysc(r(0 1)) ///
	xtitle("Percent Change in Casualties to First 30 Days", size(small)) ///
	xlabel(, labsize(vsmall)) ///
	legend(order(2 5) si(small) ///
	label(2 "Most Important Problem: Domestic") label(5 "Most Important Problem: Defense" "      ")  rowgap(*.7) col(1) ring(0) position(8)  region(lc(none)fcolor(none)))   ///
  	graphregion(margin(large) )
  	  	graph save War_House, replace
	graph export "War_House.pdf", replace

	
/*Figure 2b, Senate*/	

use War_Senate_MIP
set scheme s1mono
twoway (rarea ul ll day30_change, fc(gs13) lc(bg)) ///
	(line b day30_change, lcolor(black) lpattern(solid)) ///
 (line ul2 day30_change, lcolor(black) lpattern(dot) lwidth(medthick)) ///
	(line ll2 day30_change, lcolor(black) lpattern(dot) lwidth(medthick))  ///
	(line b2 day30_change, lcolor(black) lpattern(dash)) ///
	(scatter where day30_change if day30_change>=-1 & day30_change<=30, ms(none) mlabel(pipe) mlabpos(0)), ///
	ytitle("Probability of Vote in Favor of President's Position" "Senate, All Votes", size(small)) ///
	ylabel(0 (0.2) 1, labsize(vsmall)) ///
	ysc(r(0 1)) ///
	xtitle("Percent Change in Casualties to First 30 Days", size(small)) ///
	xlabel(, labsize(vsmall)) ///
	legend(order(2 5) si(small) ///
	label(2 "Most Important Problem: Domestic") label(5 "Most Important Problem: Defense" "      ")  rowgap(*.7) col(1) ring(0) position(8)  region(lc(none)fcolor(none)))   ///
  	graphregion(margin(large) )
  	  	graph save War_Senate, replace
	graph export "War_Senate.pdf", replace
	


/*Figure 3*/

use "HouseAll.dta"
append using HouseWar.dta
append using SenateAll.dta
append using SenateWar.dta
append using names.dta
replace group=1.1 in 1
replace group=0.9 in 3
replace group=2.1 in 2
replace group=1.9 in 4
replace chamber=2 in 5/8
replace group=0.5 in 5
replace group=2.5 in 8
label define Group 1 "All Issues" 2 "During War"
label values group Group


gen upper=pred+(1.96*std)
gen lower=pred-(1.96*std)

set scheme s1mono
twoway ///
	(scatter pred group if chamber == 2, mc(gs10)) ///
	(rcap lower upper group if chamber == 2, lc(gs10)) ///
	(scatter pred group if chamber == 1, mc(gs5)) ///
	(rcap lower upper group if chamber == 1, lc(gs5)), ///
	yline(0, lcolor(gs2) lwidth(thin) lpattern(dash)) ///
	ylabel(-.4 (.2) .4, labsize(small)) ytitle("Marginal Effects of Support for President Position", size(small)) ///
	xtitle("") xlabel(1 2,valuelabel labsize(small)) ///
	legend(label (1 "House") label(3 "Senate") order(3 1) col(1) ring(0) position(10) region(lc(none)) ) ///
  	graphregion(margin(large))
	  	  	graph save Dotplot, replace

